﻿<%@ page contentType="text/html; charset=UTF-8" %>

<!-- 商家商品 -->


<div class="bar_seach_div">

查询条件：<input id="s_shopgood_name" name="s_shopgood_name" type="text" class="box-input">&nbsp;&nbsp;
<input id="s_shopgood" type="button" class="btns" value="查  询">
</div>

<div style="padding: 5px;"><table id="shopgood_grid"></table></div>   
<div style="padding: 5px;"><div id="shopgood_page"></div>


<div id="shopgood_dialog_index" title=" 商家商品操作"  class="easyui-dialog" >
<form id="shopgood_form_index" name="shopgood_form_index" style="width:486px;" class="ui-form" method="POST">
    <div id="shopgood_index_errmsg"></div>
    <table width="100%" align="center" border="0" cellspacing="0" cellpadding="0" class="jkt-tableStyle">

	<tr>
        <td class="bluetd" align="right">名称：</td>
        <td class="bluetd" align="left">
          <input id="shopgood_name_index"  class="easyui-validatebox" type="text"/>
        </td>
     </tr>     <tr>
        <td class="bluetd2" align="right">商家ID：</td>
        <td class="bluetd2" align="left">
          <input id="shopgood_shopId_index" class="easyui-combobox"  />
        </td>
     </tr>
	<tr>
        <td class="bluetd" align="right">现金价格：</td>
        <td class="bluetd" align="left">
          <input id="shopgood_cashPrice_index"  class="easyui-validatebox" type="text"/>
        </td>
     </tr>     <tr>
        <td class="bluetd2" align="right">玫瑰价格：</td>
        <td class="bluetd2" align="left">
          <input id="shopgood_rosePrice_index"  class="easyui-validatebox" data-options="required:true"  type="text" />
        </td>
     </tr>
     <!-- shopgood_imageurl_index  shopgood_picurl_index -->
	<tr>
        <td class="bluetd" align="right">效果图：</td>
        <td class="bluetd" align="left">
          <img id="pictureImage" name="pictureImage"  src="${msUrl}resources/images/mypic/picbox3.jpg" alt="pic"   width="100"  height="100"  />
        </td>
     </tr>     
     <tr>
        <td class="bluetd2" align="right">图片：</td>
        <td class="bluetd2" align="left">
         <input type="file" id="file" name="file" />
         <input type="button" value="上传" onclick="ajaxFileUpload();"> 
         <input id="shopgood_imageurl_index"   type="hidden" />
         <input id="shopgood_picurl_index"   type="hidden" />
        </td>
     </tr>
	<tr>
        <td class="bluetd" align="right">概要：</td>
        <td class="bluetd" align="left">
          <input id="shopgood_summary_index"  class="easyui-validatebox" type="text"/>
        </td>
     </tr>     <tr>
        <td class="bluetd2" align="right">介绍说明：</td>
        <td class="bluetd2" align="left">
          <input id="shopgood_explains_index"  class="easyui-validatebox" data-options="required:true"  type="text" />
        </td>
     </tr>
<!--  
	<tr>
        <td class="bluetd" align="right">内容(备用)：</td>
        <td class="bluetd" align="left">
          <input id="shopgood_content_index"  class="easyui-validatebox" type="text"/>
        </td>
     </tr>
 -->     
     
      <tr>
        <td colspan="2" align="center">
         <input type="button" class="btns" id="shopgood_index_bt" value="提  交" style="margin-top:8px;" />&nbsp;&nbsp;
         <input type="button" class="btns" id="shopgood_close" value="关  闭" style="margin-top:8px;" />
      </td>
</tr>
</table>
</form>
</div> 

<script>

	//关闭弹出窗口
	closeUIDialog('shopgood_dialog_index');
    var shopgoodvalidate,shopgoodids='',shopgoodsave=true;//本页面变量
     /**jqGrid列表*/
	jQuery("#shopgood_grid").jqGrid({
		// caption: 
	    //     '<a href="javascript:fun_shopgood_add()"  class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-edit\'">新增</a>' +
	    //     '<a href="javascript:fun_shopgood_update()" class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-save\'">修改</a>' +
	    //     '<a href="javascript:fun_shopgood_delete()" class="easyui-linkbutton" data-options="plain:true,iconCls:\'icon-cancel\'">删除</a>',
        datatype: "json", //JSON格式数据
        hidegrid: false, //不显示收缩
        url:'barapp/ShopGood/list.do', //请求后台返回列表数据的URL 
        forceFit: false,//调整宽度不改变表格宽度
        //width: jqGridWidth,   //resources/js/constant.js
        //height: jqGridHeight, //resources/js/constant.js
        autowidth:false,   //取消容器的自动宽度
        colNames:[
        '编号'
        ,'名称'
        ,'商家ID'
        ,'商家名'
        ,'现金价格'
        ,'玫瑰价格'
        ,'图片1'
        ,'图片2'
        ,'概要'
        ,'介绍说明'
        ,'内容(备用)'
        //,'操作'
	    ],
	    //要呈现字段的属性设置
	    //sortable:设置该字段是否进行排序,sorttype:排序的数据类型 
        colModel:[
        {name:'id',index:'id', width:2,sorttype:'int',sortable:false}  
        ,{name:'name',index:'name',width:100,sortable:false}
        ,{name:'shopId',index:'shopId',width:70,sortable:false}
        ,{name:'shopName',index:'shopName',width:70,sortable:false}
        ,{name:'cashPrice',index:'cashPrice',width:40,sortable:false}
        ,{name:'rosePrice',index:'rosePrice',width:40,sortable:false}
        ,{name:'imageurl',index:'imageurl',width:80,sortable:false,formatter : fun_formatGoodImageurl}
        ,{name:'picurl',index:'picurl',width:80,sortable:false,formatter : fun_formatGoodPicurl}
        ,{name:'summary',index:'summary',width:80,sortable:false}
        ,{name:'explains',index:'explains',width:80,sortable:false}
        ,{name:'content',index:'content',width:80,sortable:false}
        //,{name:'act',        index:'act',   align:'center',     width:150}
        ],
        multiselect: true,//禁止多选
        multiboxonly:true,
        toolbar:[true,'top'],
        rowNum:10, 
        rowList:[10,20,30,50,100,500], 
        viewrecords: true, 
        sortname:  "id" , //默认排序的列名    
        sortorder: "desc",
        pager: '#shopgood_page', 
        jsonReader: {     
          root: 'dataRows',   
          repeatitems : false     
        }
        //,caption:'商家商品 列表'       
       // ,gridComplete: function(){  
          //  var ids = $("#shopgood_grid").jqGrid('getDataIDs');  
           // for(var i=0, j=ids.length; i < j; i++){  
              //  var cl = ids[i];  
               // be = "<input style='height:22px;width:40px;' type='button' value='编辑' onclick=\"fun_shopgood_update();\"  />&nbsp;&nbsp;";   
                //se = "<input style='height:22px;width:40px;' type='button' value='保存' onclick=\"$('#jqGridId').saveRow('"+cl+"');\"  />&nbsp;&nbsp;";  
               // se = "<input style='height:22px;width:40px;' type='button' value='删除' onclick=\"fun_shopgood_delete();\"  />&nbsp;&nbsp;";   
               // ce = "";
                //$("#shopgood_grid").jqGrid('setRowData',ids[i], {act: be + se + ce});  
           // }
        //}
    })
    
    $("#t_shopgood_grid").removeClass("ui-userdata ui-state-default"); //删样式
	$("#t_shopgood_grid").append("<div style='height:32px;' class='ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix'><span class='ui-jqgrid-title'>"
	  +"<a data-options='plain:true,iconCls:\'icon-edit\'' class='easyui-linkbutton l-btn l-btn-plain' href='javascript:fun_shopgood_add()' group='' id=''><span class='l-btn-left'><span class='l-btn-text icon-edit l-btn-icon-left'>新增</span></span></a>"
	  +"<a data-options='plain:true,iconCls:\'icon-save\'' class='easyui-linkbutton l-btn l-btn-plain' href='javascript:fun_shopgood_update()' group='' id=''><span class='l-btn-left'><span class='l-btn-text icon-save l-btn-icon-left'>修改</span></span></a>"
	  +"<a data-options='plain:true,iconCls:\'icon-cancel\'' class='easyui-linkbutton l-btn l-btn-plain' href='javascript:fun_shopgood_delete()' group='' id=''><span class='l-btn-left'><span class='l-btn-text icon-cancel l-btn-icon-left'>删除</span></span></a>"
	  +"</span></div> ");//列表头

    //$("#t_shopgood_grid").append("<div class='bar_grid_add_div' > <a href='javascript:void(0)' onclick=\"fun_shopgood_add()\" >新增</a></div>");//列表头
    //$("#t_shopgood_grid").hide();//隐藏标题栏
    jQuery("#shopgood_grid").jqGrid('hideCol',['picurl','shopId','content','id']);//隐藏列
    $("#shopgood_grid").closest(".ui-jqgrid-bdiv").css({ 'overflow-x' : 'hidden' });//隐藏横向滚动条
    
    var shopgood_list_saveflag = true;
    
    /***/
    $('#shopgood_index_bt').unbind('click');
    
    /**列表格式化  begin */
    function fun_formatGoodImageurl(cellvalue, options, rowObject){
    	var str = "<img src='"+rowObject.imageurl+"' width='50' height='50'/> ";
    	return str; 
    }
    function fun_formatGoodPicurl(cellvalue, options, rowObject){
    	var str = "<img src='"+rowObject.picurl+"' width='50' height='50'/> ";
    	return str; 
    }
    
    /**列表格式化  end */    
    
    /**新增操作-打开窗口*/
    function fun_shopgood_add(){
		$("#shopgood_form_index")[0].reset();
		shopgood_list_saveflag = true;
        openUIDialog('shopgood_dialog_index', true, 560, 420);
	}
    //关闭窗口
    $('#shopgood_close').click(function(){
        $("#shopgood_dialog_index").dialog('close');
    })
    
    /**点击按妞*/
    $('#shopgood_index_bt').click(function(){
         //if(rulesByValidator(shopgoodvalidate)){
             if(shopgoodsave){
                 shopgood_add_submit();
             }else{
                 shopgood_update_submit();
             }
         //}
     })
     
     //新增提交
     function  shopgood_add_submit(){
    	var shopgood_shopId_index = $("#shopgood_shopId_index").combobox("getValue") ;
        var shopgoodJson="{'id':'','name':'"+$('#shopgood_name_index').val()+"','shopId':'"+shopgood_shopId_index+"','cashPrice':'"+$('#shopgood_cashPrice_index').val()+"','rosePrice':'"+$('#shopgood_rosePrice_index').val()+"','imageurl':'"+$('#shopgood_imageurl_index').val()+"','picurl':'"+$('#shopgood_picurl_index').val()+"','summary':'"+$('#shopgood_summary_index').val()+"','explains':'"+$('#shopgood_explains_index').val()+"','content':'"+$('#shopgood_content_index').val()+"'}";  
         $.ajax({
             type: "POST",
             url:"barapp/ShopGood/save.do",
             data:{
                 shopgoodJson : shopgoodJson
             },
             dataType: "json",
             contentType: "application/x-www-form-urlencoded; charset=UTF-8",
             success:function(json){
                 if(json.success){
                     $("#shopgood_grid").trigger("reloadGrid");
                     $.messager.alert('操作提示', '操作成功!');
                 }else{
                	 $.messager.alert('操作提示', '操作失败!');
                 }
             }
         })
     }
     

     /**修改操作*/
     function fun_shopgood_update(){
         var id =$("#shopgood_grid").jqGrid('getGridParam','selrow');
         if(typeof(id) =="string"){
             rowData=jQuery("#shopgood_grid").jqGrid('getRowData',id);  
 		    //$("#shopgood_dialog_index").dialog('option' , 'title',['修改 商家商品']);
 		    $("#shopgood_form_index")[0].reset();
 		    //shopgoodvalidate.resetForm(); //重置验证状态
 		    //$("#shopgood_dialog_index").dialog("open");
 		    openUIDialog('shopgood_dialog_index', true, 560, 420);
             load_shopgood_data();
             shopgoodsave=false;
         }else{
        	 $.messager.alert('操作提示', '请至少选择一条记录再操作!'); 
         }
 	}
   /**修改加载数据*/
 	function load_shopgood_data(){
 	  $("#shopgood_name_index").val(rowData.name);
 	  $("#shopgood_shopId_index").combobox("setValue",rowData.shopId);
 	  $("#shopgood_cashPrice_index").val(rowData.cashPrice);
 	  $("#shopgood_rosePrice_index").val(rowData.rosePrice);
 	  $("#shopgood_imageurl_index").val(rowData.imageurl);
 	  $("#shopgood_picurl_index").val(rowData.picurl);
 	  $("#shopgood_summary_index").val(rowData.summary);
 	  $("#shopgood_explains_index").val(rowData.explains);
 	  $("#shopgood_content_index").val(rowData.content);
 	}
    //修改提交
    function  shopgood_update_submit(){
    	var shopgood_shopId_index = $("#shopgood_shopId_index").combobox("getValue") ;
        var shopgoodJson="{'id':'"+rowData.id+"','name':'"+$('#shopgood_name_index').val()+"','shopId':'"+shopgood_shopId_index+"','cashPrice':'"+$('#shopgood_cashPrice_index').val()+"','rosePrice':'"+$('#shopgood_rosePrice_index').val()+"','imageurl':'"+$('#shopgood_imageurl_index').val()+"','picurl':'"+$('#shopgood_picurl_index').val()+"','summary':'"+$('#shopgood_summary_index').val()+"','explains':'"+$('#shopgood_explains_index').val()+"','content':'"+$('#shopgood_content_index').val()+"'}";  
        $.ajax({
            type: "POST",
            url:"barapp/ShopGood/update.do",
            data:{
                shopgoodJson : shopgoodJson
            },
            dataType: "json",
            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
            success:function(json){
                if(json.success){
                    $("#shopgood_grid").trigger("reloadGrid");
                    $.messager.alert('操作提示', '操作成功!'); 
                }else{
               	 $.messager.alert('操作提示', '操作失败!'); 
                }
            }
       })
    }
	 
	 
	//删除-开始-验证
	function fun_shopgood_delete(){
       
        
	      var gr = $("#shopgood_grid").jqGrid('getGridParam','selrow');
	      if(gr != null)
	      {
	         var rowData = jQuery("#shopgood_grid").jqGrid('getRowData', gr);
	         $.messager.confirm('删除提示','您确认要删除?', function(r)
	         {
	            if(r)
	            {
	            	fun_shopgood_del(rowData.id);
	            }
	         });
	      }
	      else
	      {
	         $.messager.alert('提示','请先选中一行数据!!');
	      }
        
    }
	//删除-提交数据-操作
    function fun_shopgood_del(ids){
	    $.ajax({
            type: "POST",
            url:"barapp/ShopGood/delete.do?s_ids="+ids,
            dataType: "json",
            data:{
            	ids : ids
            },
            success:function(json){
                 if(json.success){
                	  $.messager.alert('操作提示', '操作成功！');
                      $("#shopgood_grid").trigger("reloadGrid");
                 }else{
                	  $.messager.alert('操作提示', '操作失败！');
                 }
            }
        })
    }
      
	//注意:web服务器 utf-8配置
	$('#s_shopgood').click(function(){
         var s_name=encodeURI($('#s_shopgood_name').val());
         $("#shopgood_grid").setGridParam({url:'barapp/ShopGood/list.do?s_name='+s_name});
         $("#shopgood_grid").trigger("reloadGrid");
    })
    
    /** jqgrid宽度高度自适应 begin */ 
    doResize();
	var t=document.documentElement.clientWidth;  
	window.onresize = function(){  
		if(t != document.documentElement.clientWidth){ 
		t = document.documentElement.clientWidth; 
		doResize(); 
		} 
	} 
    
	function doResize() { 
		var ss = getPageSize(); 
		$("#shopgood_grid").jqGrid('setGridWidth', ss.WinW-350).jqGrid('setGridHeight', ss.WinH-300); 
	}
	
	function getPageSize() { 
		//http://www.blabla.cn/js_kb/javascript_pagesize_windowsize_scrollbar.html 
		var winW, winH; 
		if(window.innerHeight) {// all except IE 
		winW = window.innerWidth; 
		winH = window.innerHeight; 
		} else if (document.documentElement && document.documentElement.clientHeight) {// IE 6 Strict Mode 
		winW = document.documentElement.clientWidth; 
		winH = document.documentElement.clientHeight; 
		} else if (document.body) { // other 
		winW = document.body.clientWidth; 
		winH = document.body.clientHeight; 
		}  // for small pages with total size less then the viewport  
		return {WinW:winW, WinH:winH}; 
	}
	/** jqgrid宽度高度自适应 begin */

	    /** 上传文件 begin **/
    function ajaxFileUpload(){ 
        $.ajaxFileUpload({
                url:'uploads/AjaxUpload/executes.do',   //用于文件上传的服务器端请求地址
                secureuri:false,        //一般设置为false
                fileElementId : 'file',   //文件上传空间的id属性  <input type="file" id="file" name="file" />
                dataType: 'JSON',    //返回值类型 一般设置为json
                async: "true",
                secureuri:false,
                contentType: "application/x-www-form-urlencoded; charset=UTF-8",
                success: function(json){
                	//$.messager.alert('Tip','上传成功');
                	var str = strsubjson(json);
		            var obj = strToObj(str); 
                    $("#pictureImage").attr("src",obj.url);//设置显示图片的URL
                    $("#pictureImage").show();
                    $("#shopgood_imageurl_index").val(obj.url); //设置提交图片的URL shopgood_imageurl_index  shopgood_picurl_index
                    $("#shopgood_picurl_index").val(obj.url);
                },
                error : function(json) {
                    alert("error");  
                }
            });
    }    
    /** 上传文件 end **/
    
	/**下拉框初始化(商家)  begin */
	from_initShopmainCombox();
	function from_initShopmainCombox() {
		$.ajax({  
			url:"barapp/ShopMain/getComboBox.do",
			  cache: false,  
			  dataType:"json",  
			  success: function(result){
				  //alert("ok"+result.list[0].id);
				  var feiqumingxiarr = new Array();
				  feiqumingxiarr =result.list;
			     $("#shopgood_shopId_index").combobox({  
			        data : feiqumingxiarr,  
			        valueField : 'id',  
			        textField : 'name' 
			    });  
			  },
			  error : function(){
				  alert("error");
			  }
			});
	}
	/**下拉框初始化(商家)  end  */
	
</script>
